package net.onceface.core.domain;

import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import net.onceface.infra.domain.AbstractEntity;

/**
 * 客户购物车
 * **/
@Entity
@Table(name = "SYS_CART")
@NamedQueries({
	@NamedQuery(name = "Cart.findCartByClientId", query = "SELECT _cart FROM Cart _cart WHERE _cart.clientId = :clientId")
})
public class Cart extends AbstractEntity{

	/**
	 * 
	 */
	private static final long serialVersionUID = 6548231674343050176L;
	
	/**
	 * 客户ID
	 * **/
	@Column(name = "CLIENT_ID")
	private Long clientId;
	
	/**
	 * 商品ID
	 * **/
	@Column(name = "PRODUCT_ID", nullable = false)
	private Long productId;
	
	/**
	 * 商品名称
	 * **/
	@Column(name = "PRODUCT_NAME", nullable = false)
	private String productName;
	
	/**
	 * 数量
	 * **/
	@Column(name = "QUANTITY", nullable = false)
	private int quantity;
	
	/**
	 * 商品图片
	 * **/
	@Column(name = "PRODUCT_PICTURE")
	private String productPicture;
	
	@Column(name = "CHECKED")
	private boolean checked;
	
	/**
	 * 商品单价
	 * **/
	@Column(name = "PRODUCT_PRICE", nullable = false)
	private double productPrice;
	
	/**
	 * 规格ID
	 * **/
	@Column(name = "SPEC_ID")
	private Long specID;
	
	/**
	 * 规格名
	 * **/
	@Column(name = "SPEC_NAME")
	private String specName;
	
	/**
	 * 是否有效
	 * **/
	@Column(name = "VALID")
	private boolean valid;
	
	/**
	 * 创建日期
	 * **/
	@Column(name = "CREATE_DATE", nullable = false ,updatable = false)
	@Temporal(TemporalType.TIMESTAMP)
	private Date createDate = new Date();
	
	public Cart(Long clientId, Long productId, String productName, int quantity, String picture){
		this.clientId = clientId;
		this.productId = productId;
		this.productName = productName;
		this.quantity = quantity;
		this.productPicture = picture;
	}
	
	public Cart(){}
	
	/**
	 * 根据用户ID 获取用户购物车内容
	 * **/
	public static List<Cart> findByClientId(Long clientId){
		 return getRepository()
				 .createNamedQuery("Cart.findCartByClientId")
				 .addParameter("clientId", clientId)
				 .list();
	}
	
	public boolean isChecked() {
		return checked;
	}

	public void setChecked(boolean checked) {
		this.checked = checked;
	}

	public Long getClientId() {
		return clientId;
	}

	public boolean isValid() {
		return valid;
	}

	public void setValid(boolean valid) {
		this.valid = valid;
	}

	public void setClientId(Long clientId) {
		this.clientId = clientId;
	}

	public Long getProductId() {
		return productId;
	}

	public void setProductId(Long productId) {
		this.productId = productId;
	}

	public String getProductName() {
		return productName;
	}

	public void setProductName(String productName) {
		this.productName = productName;
	}

	public int getQuantity() {
		return quantity;
	}

	public void setQuantity(int quantity) {
		this.quantity = quantity;
	}

	public String getProductPicture() {
		return productPicture;
	}

	public void setProductPicture(String productPicture) {
		this.productPicture = productPicture;
	}

	public double getProductPrice() {
		return productPrice;
	}

	public void setProductPrice(double productPrice) {
		this.productPrice = productPrice;
	}

	public Long getSpecID() {
		return specID;
	}

	public void setSpecID(Long specID) {
		this.specID = specID;
	}

	public String getSpecName() {
		return specName;
	}

	public void setSpecName(String specName) {
		this.specName = specName;
	}

	public Date getCreateDate() {
		return createDate;
	}

	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}

	@Override
	public String[] businessKeys() {
		// TODO Auto-generated method stub
		return null;
	}

}
